use MediaWiki\Storage\MutableRevisionSlots;
use MediaWiki\Storage\RevisionAccessException;
use MediaWiki\Storage\SlotRecord;
-use MediaWikiTestCase;
use WikitextContent;
/**
* @covers \MediaWiki\Storage\MutableRevisionSlots
*/
-class MutableRevisionSlotsTest extends MediaWikiTestCase {
+class MutableRevisionSlotsTest extends RevisionSlotsTest {
public function testSetMultipleSlots() {
$slots = new MutableRevisionSlots();
$slotA = SlotRecord::newUnsaved( 'some', new WikitextContent( 'A' ) );
$slots->setSlot( $slotA );
+ $this->assertTrue( $slots->hasSlot( 'some' ) );
$this->assertSame( $slotA, $slots->getSlot( 'some' ) );
$this->assertSame( [ 'some' => $slotA ], $slots->getSlots() );
$slotB = SlotRecord::newUnsaved( 'other', new WikitextContent( 'B' ) );
$slots->setSlot( $slotB );
+ $this->assertTrue( $slots->hasSlot( 'other' ) );
$this->assertSame( $slotB, $slots->getSlot( 'other' ) );
$this->assertSame( [ 'some' => $slotA, 'other' => $slotB ], $slots->getSlots() );
}
class RevisionSlotsTest extends MediaWikiTestCase {
+ /**
+ * @param SlotRecord[] $slots
+ * @return RevisionSlots
+ */
+ protected function newRevisionSlots( $slots = [] ) {
+ return new RevisionSlots( $slots );
+ }
+
/**
* @covers \MediaWiki\Storage\RevisionSlots::getSlot
*/
public function testGetSlot() {
$mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
$auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
- $slots = new RevisionSlots( [ $mainSlot, $auxSlot ] );
+ $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
$this->assertSame( $mainSlot, $slots->getSlot( 'main' ) );
$this->assertSame( $auxSlot, $slots->getSlot( 'aux' ) );
$slots->getSlot( 'nothere' );
}
+ /**
+ * @covers \MediaWiki\Storage\RevisionSlots::hasSlot
+ */
+ public function testHasSlot() {
+ $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+ $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
+ $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
+
+ $this->assertTrue( $slots->hasSlot( 'main' ) );
+ $this->assertTrue( $slots->hasSlot( 'aux' ) );
+ $this->assertFalse( $slots->hasSlot( 'AUX' ) );
+ $this->assertFalse( $slots->hasSlot( 'xyz' ) );
+ }
+
/**
* @covers \MediaWiki\Storage\RevisionSlots::getContent
*/
$auxContent = new WikitextContent( 'B' );
$mainSlot = SlotRecord::newUnsaved( 'main', $mainContent );
$auxSlot = SlotRecord::newUnsaved( 'aux', $auxContent );
- $slots = new RevisionSlots( [ $mainSlot, $auxSlot ] );
+ $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
$this->assertSame( $mainContent, $slots->getContent( 'main' ) );
$this->assertSame( $auxContent, $slots->getContent( 'aux' ) );
public function testGetSlotRoles_someSlots() {
$mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
$auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
- $slots = new RevisionSlots( [ $mainSlot, $auxSlot ] );
+ $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
$this->assertSame( [ 'main', 'aux' ], $slots->getSlotRoles() );
}
* @covers \MediaWiki\Storage\RevisionSlots::getSlotRoles
*/
public function testGetSlotRoles_noSlots() {
- $slots = new RevisionSlots( [] );
+ $slots = $this->newRevisionSlots( [] );
$this->assertSame( [], $slots->getSlotRoles() );
}
$mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
$auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
$slotsArray = [ $mainSlot, $auxSlot ];
- $slots = new RevisionSlots( $slotsArray );
+ $slots = $this->newRevisionSlots( $slotsArray );
$this->assertEquals( [ 'main' => $mainSlot, 'aux' => $auxSlot ], $slots->getSlots() );
}
foreach ( $contentStrings as $key => $contentString ) {
$slotsArray[] = SlotRecord::newUnsaved( strval( $key ), new WikitextContent( $contentString ) );
}
- $slots = new RevisionSlots( $slotsArray );
+ $slots = $this->newRevisionSlots( $slotsArray );
$this->assertSame( $expected, $slots->computeSize() );
}
foreach ( $contentStrings as $key => $contentString ) {
$slotsArray[] = SlotRecord::newUnsaved( strval( $key ), new WikitextContent( $contentString ) );
}
- $slots = new RevisionSlots( $slotsArray );
+ $slots = $this->newRevisionSlots( $slotsArray );
$this->assertSame( $expected, $slots->computeSha1() );
}
$rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
// NOTE: slot meta-data is never suppressed, just the content is!
- $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw can' );
- $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public can' );
+ $this->assertTrue( $rev->hasSlot( 'main' ), 'hasSlot is never suppressed' );
+ $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw meta' );
+ $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public meta' );
$this->assertNotNull(
$rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user ),
$this->assertSame( 'main', $slot->getRole(), 'getRole()' );
}
+ public function testHasSlot() {
+ $rev = $this->newRevision();
+
+ $this->assertTrue( $rev->hasSlot( 'main' ) );
+ $this->assertFalse( $rev->hasSlot( 'xyz' ) );
+ }
+
public function testGetContent() {
$rev = $this->newRevision();